#include "ForceExplosion.h"


ForceExplosion::ForceExplosion(void)
{
	srand(time(0));
	random = new RandGenerator<float>(500.0f, 1000.0f , rand());
	randomAngle = new RandGenerator<float>(0.0f, 360.0f, rand());
}


ForceExplosion::ForceExplosion(float min, float max, float minAngle, float maxAngle)
{
	srand(time(0));
	random = new RandGenerator<float>(min, max, rand());
	randomAngle = new RandGenerator<float>(minAngle, maxAngle, rand());
}

ForceExplosion::~ForceExplosion(void)
{
	delete random;
	delete randomAngle;
}

void ForceExplosion::update(int delta)
{
	if(!active)
		return;

	//CL_Vec2f force;
	//CL_Vec2f origin(0,0);
	for(std::list<Particle*>::iterator I=particles.begin(); I!=particles.end(); ++I)
	{
		//calculate random force
		Vector3f force(1.0f,0.0f,0.0f);
		force.normalize();
		float angle = (*randomAngle)();
		force.rotate(Vector3f::z_axis, angle); //rotate around random angle
		force.normalize();

		//apply force
		(*I)->force += force * (*random)();
	}

	//remove all particles (force is only applied once!)
	particles.clear();
}
